package cn.dmp.utils

import org.apache.spark.sql.Row

import scala.collection.mutable.ListBuffer

object TagsUtils {
  val hasSomeUserIdCondition =
   """
     |imei !="" or imeimd5 != "" or imeisha1 != "" or
     |idfa !="" or idfamd5 != "" or idfasha1 != "" or
     |mac !="" or macmd5 != "" or macsha1 != "" or
     |android !="" or androidmd5 != "" or androidsha1 != "" or
     |openudid !="" or openudidmd5 != "" or openudidsha1 != ""
   """.stripMargin


  def getAllUserId(row:Row):ListBuffer[String]={
    val userIds = new ListBuffer[String]()
      if (row.getAs[String]("imei").nonEmpty ) userIds.append("IM:"+row.getAs[String]("imei").toUpperCase())
      if (row.getAs[String]("idfa").nonEmpty ) userIds.append("DF:"+row.getAs[String]("idfa").toUpperCase())
      if (row.getAs[String]("mac").nonEmpty ) userIds.append("MC:"+row.getAs[String]("mac").toUpperCase())
      if (row.getAs[String]("android").nonEmpty ) userIds.append("AD:"+row.getAs[String]("android").toUpperCase())
      if (row.getAs[String]("openudid").nonEmpty ) userIds.append("OU:"+row.getAs[String]("openudid").toUpperCase())

      if (row.getAs[String]("imeimd5").nonEmpty ) userIds.append("IMM:"+row.getAs[String]("imeimd5").toUpperCase())
      if (row.getAs[String]("idfamd5").nonEmpty ) userIds.append("DFM:"+row.getAs[String]("idfamd5").toUpperCase())
      if (row.getAs[String]("macmd5").nonEmpty ) userIds.append("MCM:"+row.getAs[String]("macmd5").toUpperCase())
      if (row.getAs[String]("androidmd5").nonEmpty ) userIds.append("ADM:"+row.getAs[String]("androidmd5").toUpperCase())
      if (row.getAs[String]("openudidmd5").nonEmpty ) userIds.append("OUM:"+row.getAs[String]("openudidmd5").toUpperCase())

      if (row.getAs[String]("imeisha1").nonEmpty ) userIds.append("IMS:"+row.getAs[String]("imeisha1").toUpperCase())
      if (row.getAs[String]("idfasha1").nonEmpty ) userIds.append("DFS:"+row.getAs[String]("idfasha1").toUpperCase())
      if (row.getAs[String]("macsha1").nonEmpty ) userIds.append("MCS:"+row.getAs[String]("macsha1").toUpperCase())
      if (row.getAs[String]("androidsha1").nonEmpty ) userIds.append("ADS:"+row.getAs[String]("androidsha1").toUpperCase())
      if (row.getAs[String]("openudidsha1").nonEmpty ) userIds.append("OUS:"+row.getAs[String]("openudidsha1").toUpperCase())



    userIds
  }


}
